package test3;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Person implements Comparable<Person>{
	private String name;
	private int age;
	private boolean gender;
	
	public Person(String name, int age, boolean gender) {
		this.name = name;
		this.age = age;
		this.gender = gender;
	}

	public String toString() {
		return name+"-"+age+"-"+gender;
	}
	
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Person other = (Person) obj;
		if (age != other.age)
			return false;
		if (gender != other.gender)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	public int getAge() {
		return age;
	}

	public int compareTo(Person o) {
		// TODO Auto-generated method stub
		if(name.compareTo(o.name)==0)
			return getAge()-o.getAge();
		return name.compareTo(o.name);
	}
	
}
class Student extends Person{
	private String stuNo;
	private String clazz;
	
	public Student(String name, int age, boolean gender, String stuNo, String clazz) {
		super(name, age, gender);
		this.stuNo = stuNo;
		this.clazz = clazz;
	}

	public String toString() {
		return "Student:"+super.toString()+"-"+stuNo+"-"+clazz;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Student other = (Student) obj;
		if (clazz == null) {
			if (other.clazz != null)
				return false;
		} else if (!clazz.equals(other.clazz))
			return false;
		if (stuNo == null) {
			if (other.stuNo != null)
				return false;
		} else if (!stuNo.equals(other.stuNo))
			return false;
		return true;
	}
	
}
class Company{
	private String name;

	public Company(String name) {
		this.name = name;
	}
	
	public String toString() {
		return name;
	}
	
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Company other = (Company) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
}
class Employee extends Person{
	private Company company;
	private double salary;
	
	public Employee(String name, int age, boolean gender, double salary, Company company) {
		super(name, age, gender);
		this.company = company;
		this.salary = salary;
	}

	public String toString() {
		return "Employee:"+super.toString()+"-"+company+"-"+salary;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Employee other = (Employee) obj;
		if (company == null) {
			if (other.company != null)
				return false;
		} else if (!company.equals(other.company))
			return false;
		DecimalFormat df=new DecimalFormat("#.#");
		String a=df.format(this.salary);
		double a1=Double.parseDouble(a);
		String b=df.format(other.salary);
		double b1=Double.parseDouble(b);
		if(a1!=b1)
		return false ;
		return true;
	}
}
public class Test2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		ArrayList<Person> personList=new ArrayList<>();
		String str=in.next();
		while(str.equals("s")||str.equals("e")) {
			if(str.equals("s")) {
				Student stu=new Student(in.next(), in.nextInt(), in.nextBoolean(), in.next(), in.next());
				personList.add(stu);
			}
			if(str.equals("e")) {
				Employee employee=new Employee(in.next(), in.nextInt(), in.nextBoolean(), in.nextDouble(), new Company(in.next()));
				personList.add(employee);
			}
			str=in.next();
		}
		Collections.sort(personList);
		for(int i=0;i<personList.size();i++)
			System.out.println(personList.get(i));
		ArrayList<Person> stuList=new ArrayList<>();
		ArrayList<Person> empList=new ArrayList<>();
		String str1=in.next();
		if(!str1.equals("exit")) {
			for(int i=0;i<personList.size();i++) {
			if(personList.get(i).getClass().equals(Student.class)) {
				if(!stuList.contains(personList.get(i)))
				stuList.add(personList.get(i));
			}
			else if(personList.get(i).getClass().equals(Employee.class)) {
				if(!empList.contains(personList.get(i)))
				empList.add(personList.get(i));
			}		
			}
		}
		System.out.println("stuList");
		for(int i=0;i<stuList.size();i++)
			System.out.println(stuList.get(i));
		System.out.println("empList");
		for(int i=0;i<empList.size();i++)
			System.out.println(empList.get(i));
	
		
		
	}

}

